<!--
 * @author dumeng
 p培训班问题反馈列表
 -->
<template>
  <section class="law-consult-main">
    <el-collapse-transition>
      <section v-show="searchshow" class="main-search merge">
        <span class="svg-container">
          <svg-icon icon-class="search" />
        </span>
        <el-input v-model.trim="listQuery.commentContent" placeholder="输入反馈内容搜索" class="search-input" @keyup.enter.native="handleFilter" />
        <section class="search-btn">
          <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
          <el-button type="primary" @click="handleReset">重置</el-button>
        </section>
      </section>
    </el-collapse-transition>

    <section class="main-buttons">
      <section class="main-buttons-title">
        <span>问题反馈</span>
      </section>
      <section class="main-buttons-btns">
        <el-button style="margin-left: 10px;" @click="handleBack">返回 </el-button>
      </section>
    </section>
    <section class="main-tab">
      <el-tabs v-model="active" @tab-click="handleTabClick">
        <el-tab-pane v-for="item in tabs" :key="item.id" :label="item.label" :name="item.name" />
      </el-tabs>
    </section>

    <section class="main-table">
      <v-table :list="list" :tag="tag" :list-loading="listLoading" :filter-column="filtercolumn" :selection="false">
        <el-table-column label="操作" fixed="right" align="center" min-width="120" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="handleReplay(scope.row)">回复</el-button>
            <!-- <el-button v-if="active === '3'" type="text" size="mini" @click="handleDel(scope.row.id)">删除</el-button>
            <el-button v-if="active === '3'" type="text" size="mini" @click="handlePublish(scope.row)">{{
              scope.row.isPush === '1' ? '取消发布' : '发布'
            }}</el-button> -->
          </template>
        </el-table-column>
      </v-table>
      <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </section>
  </section>
</template>
<script>
import Pagination from '@/components/Pagination'
import VTable from '@/components/Table'
import { queryPage, updateState, del, getMaxSort, getDictByCode } from '../api'
import permission from '@/directive/permission/index.js'

export default {
  name: 'LawconsultMain',
  components: { Pagination, VTable },
  directives: { permission },
  data() {
    return {
      areaId: '',
      listQuery: {
        page: 1,
        limit: 10,
        commentContent: ''
      },
      searchshow: true,
      search: {
        commentContent: '',
        source: '',
        briefIntroduction: ''
      },
      list: [],
      total: 0,
      listLoading: false,
      active: '1',
      tabs: [
        {
          label: '未回复',
          name: '1'
        },
        {
          label: '已回复',
          name: '2'
        }
      ],
      tag: 'PXZX'
    }
  },
  created() {
    if (this.$route.query.t) {
      this.active = this.$route.query.t
    }
    this.areaId = this.$route.query.id
    this.getList()
  },
  methods: {
    handleBack() {
      this.$router.push({ path: this.$filterPath('index') })
    },
    /**
     * 获取字典
     */
    getDict(code) {
      return new Promise((resolve, reject) => {
        getDictByCode(code)
          .then((response) => {
            this.dict[code] = response.data.data && response.data.data.length > 0 ? response.data.data[0].list : []
          })
          .catch((error) => {
            reject(error)
          })
      })
    },
    /**
     * 查看
     */
    handleReplay(row) {
      this.$router.push({ path: this.$filterPath('feedbackManage'), query: { i: row.id, t: this.active, areaId: this.areaId } })
    },
    /**
     * 发布/取消发布
     */
    handlePublish(row) {
      this.$confirm(row.isPush === '1' ? '确认取消发布？' : '确认发布？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          updateState({ id: row.id, isPush: row.isPush === '1' ? '0' : '1' }).then((res) => {
            if (res.data.code === '200') {
              this.$message({
                type: 'success',
                message: '操作成功!'
              })
              this.getList()
            }
          })
        })
        .catch(() => {})
    },
    getMaxSort() {
      return new Promise((resolve, reject) => {
        getMaxSort({ consultativeType: 'PXZX' })
          .then((res) => {
            resolve(res.data.data)
          })
          .catch(() => {
            resolve('')
          })
      })
    },
    /**
     * 编辑
     * */
    handleEdit(row) {
      this.$router.push({ path: this.$filterPath('edit'), query: { i: row.id, t: this.active, pt: 'u' } })
    },
    /**
     * 删除
     * */
    handleDel(ids) {
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          const loading = this.$loading({
            lock: true,
            text: '请稍后',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.3)'
          })
          return new Promise((resolve, reject) => {
            del({ id: ids })
              .then(() => {
                loading.close()
                this.$message({
                  title: '成功',
                  message: '删除成功',
                  type: 'success',
                  duration: 2000
                })
                this.getList()
              })
              .catch((error) => {
                loading.close()
                reject(error)
              })
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },

    handleTabClick() {
      this.listQuery.page = 1
      if (this.active === '3') {
        this.tag = 'flzx-selected'
      } else {
        this.tag = 'flzx'
      }
      this.getList()
    },

    filtercolumn(scope, item) {
      return scope.row[item]
    },

    handleReset() {
      this.listQuery.page = 1
      this.listQuery.commentContent = ''
      for (const i in this.search) {
        if (this.search['' + i + ''] instanceof Array) {
          this.search['' + i + ''] = []
        } else {
          this.search['' + i + ''] = ''
        }
      }
      this.getList()
    },

    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },

    getList(obj) {
      this.listLoading = true
      const url = this.active === '3' ? '/backend/excellentConsultLog/queryPage' : '/backend/consultativeLog/queyrPage'
      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit,
        consultativeType: 'PXZX',
        commentContent: this.listQuery.commentContent,
        classId: this.areaId
      }
      if (this.active !== '3') {
        query.type = this.active
      }
      return new Promise((resolve, reject) => {
        queryPage(query, url)
          .then((response) => {
            this.list = response.data.data.rows || []
            this.total = response.data.data.total || 0
            this.listLoading = false
          })
          .catch((error) => {
            reject(error)
            this.listLoading = false
          })
      })
    }
  }
}
</script>
<style lang="scss">
.law-consult-main {
  padding: 10px;
  .main-search {
    background-color: #fff;
    padding: 0 10px;
    .svg-container {
      padding: 0 5px 0 10px;
      color: #bfced6;
      vertical-align: middle;
      display: inline-block;
    }
    .search-input {
      width: 60%;
      position: relative;
      &:after {
        content: '';
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }
      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;
        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }
    .search-btn {
      display: inline-block;
      float: right;
      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }
      .search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
        margin-left: 10px;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }

    &.separate {
      .search-inner {
        padding-top: 10px;
        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #a6a6a6;
            font-weight: 400;
          }
          .el-input {
            position: relative;
            &.el-date-editor input {
              padding-left: 30px;
            }
            .el-input__inner {
              border: none;
              padding: 0;
            }
            &:after {
              content: '';
              height: 1px;
              background-color: #e2e3e8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }
      .search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }

  .main-tab {
    width: 100%;
    margin: 10px 0;
    padding: 0 10px;
    background-color: #fff;
    display: flex;
    border-radius: 4px;
    .el-tabs__nav-wrap::after {
      display: none;
    }
    .el-tabs__header {
      margin: 0;
    }
  }

  .main-buttons {
    display: flex;
    line-height: 36px;
    margin-top: 10px;
    .main-buttons-title {
      flex: 1;
      height: 36px;
      line-height: 36px;
      font-size: 16px;
      font-weight: bold;
      color: rgba(51, 51, 51, 1);
    }
  }
}
</style>
